import UserUtils from "../data/user";
import {
    PixelRatio,
    Dimensions,
    Platform
} from 'react-native';

export let screenW = Dimensions.get('window').width;
export let screenH = Dimensions.get('window').height;
// iPhoneX
const X_WIDTH = 375;
const X_HEIGHT = 812;

let checkLogin = () => {
    return new Promise((resolve, reject) => {
        UserUtils.loadUserInfo().then((user) => {
            let token = user.token;
            let uid = user.uid;
            if (uid && token) {
                return resolve();
            } else {
                return reject();
            }
        })
    })
}


export function replacePhone(phone) {
    if (phone.length == 11) {
        return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
    } else {
        return phone
    }
}

export default {checkLogin}


/**
 * 判断是否为iphoneX
 * @returns {boolean}
 */
export function isIphoneX() {
    return (
        Platform.OS === 'ios' &&
        ((screenH === X_HEIGHT && screenW === X_WIDTH) ||
            (screenH === X_WIDTH && screenW === X_HEIGHT))
    )
}

/**
 * 根据是否是iPhoneX返回不同的样式
 * @param iphoneXStyle
 * @param iosStyle
 * @param androidStyle
 * @returns {*}
 */

export function ifIphoneX(iphoneXStyle, iosStyle, androidStyle) {
    if (isIphoneX()) {
        return iphoneXStyle;
    } else if (Platform.OS === 'ios') {
        return iosStyle
    } else {
        if (androidStyle) return androidStyle;
        return iosStyle
    }
}